package com.qiye.pointsserver.service;

import com.qiye.pointsserver.model.entity.Pointslog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface PointsLogRepository extends JpaRepository<Pointslog, Long> {

    @Transactional
    @Modifying
    @Query(value = "UPDATE sys_pointslog SET time = CASE WHEN time > 0 THEN time - 1 ELSE 0 END", nativeQuery = true)
    void decrementTimeEveryDay();



    // todo 提前一个月
    @Query(value = "SELECT * FROM sys_pointslog WHERE time = '30' ", nativeQuery = true)
    List<Pointslog> findUserIdsWithTimeEquals7();

}
